cd ~/codespace

" 定义前缀建为',', 默认前缀建为'\'
let mapleader=","

" 显示隐藏文件
let NERDTreeShowHidden=1

" 设置gvim字体
set guifont=Courier\ 17


set nu
" set rnu
set autoindent
set tabstop=4
set shiftwidth=4
set expandtab
syntax on
filetype indent on " 开启文件类型检查，并且载入与该类型对应的缩进规则。比如，如果编辑的是.py文件，Vim 就是会找 Python 的缩进规则~/.vim/indent/python.vim
set cursorline
" set cursorcolum

" vim出现(>4;2m)这样的奇怪符号 - it is a problem of modifyOtherKeys.
let &t_TI = ""
let &t_TE = ""

" 打开鼠标操作
set mouse=a

" colorscheme molokai
" colorscheme wombat
" colorscheme lyla
" colorscheme mustang
" colorscheme solarized
" colorscheme github
" colorscheme shine
" colorscheme codedark
" colorscheme gruvbox
colorscheme intellij_light
" colorscheme onehalfdark
" colorscheme onehalflight


" Allow saving of files as sudo when I forgot to start vim using sudo
" cmap w!! w !sudo tee > /dev/null %


" 关闭声音
:set vb t_vb=
" 关闭闪屏，因为关闭声音后，vim会用闪屏提示，多按一次esc也会闪
au GuiEnter * set t_vb=

" 设置行号颜色
:highlight LineNr guifg=grey
" 设置行号背景色
" :highlight LineNr guibg=black

" 设置编码
:set encoding=utf-8
:set fileencodings=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
:set termencoding=utf-8




" vim添加复制（crtl+c）,粘贴（ctrl+v）ctrl+A 等快捷键
" source /usr/share/vim/vim90/mswin.vim

" win gvim 配置 
if(has("win32") || has("win95") || has("win64") || has("win7") || has("win10"))
    " 下面是复制了win下gvim设置安装后的_vimrc文件中内容
    " Vim with all enhancements
    source $VIMRUNTIME/vimrc_example.vim

    " Remap a few keys for Windows behavior
    source $VIMRUNTIME/mswin.vim

    " Mouse behavior (the Windows way)
    behave mswin

    " Use the internal diff if available.
    " Otherwise use the special 'diffexpr' for Windows.
    if &diffopt !~# 'internal'
        set diffexpr=MyDiff()
    endif
    function MyDiff()
        let opt = '-a --binary '
        if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
        if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
        let arg1 = v:fname_in
        if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
        let arg1 = substitute(arg1, '!', '\!', 'g')
        let arg2 = v:fname_new
        if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
        let arg2 = substitute(arg2, '!', '\!', 'g')
        let arg3 = v:fname_out
        if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
        let arg3 = substitute(arg3, '!', '\!', 'g')
        if $VIMRUNTIME =~ ' '
            if &sh =~ '\<cmd'
                if empty(&shellxquote)
                    let l:shxq_sav = ''
                    set shellxquote&
                endif
                let cmd = '"' . $VIMRUNTIME . '\diff"'
            else
                let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
            endif
        else
            let cmd = $VIMRUNTIME . '\diff'
        endif
        let cmd = substitute(cmd, '!', '\!', 'g')
        silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
        if exists('l:shxq_sav')
            let &shellxquote=l:shxq_sav
        endif
    endfunction

    " win下gvim菜单栏乱码
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim

    " win gvim 设置字体
    set guifont=Cascadia\ Code:h14

    " win gvim 设置光标和光标闪烁
    set guicursor=n-v-c:ver20-blinkwait700-blinkon600-blinkoff300

    " gvim在Windows中最大化启动
    autocmd GUIEnter * simalt ~x
endif

" 解决插入模式下delete/backspce键失效问题
set backspace=2

"==============================================================================
" 创建文件时自动设置头部注释信息 (已用ultisnips代替)
"==============================================================================
""autocmd BufNewFile *.php,*.go exec ":call SetTitle()"
""func SetTitle()
""    if expand("%:e") == 'php'
""        call setline(1, '<?php')
""        call append(line('.'), '// ====================================')
""        call append(line('.')+1, '')
""        call append(line('.')+2, '// Author:            韩孝龙')
""        call append(line('.')+3, '// Email:             18301805881@163.com')
""        call append(line('.')+4, '// Created Time:      '.strftime("%F %T"))
""        call append(line('.')+5, '// Description:       ')
""        call append(line('.')+6, '')
""        call append(line('.')+7, '// ====================================')
""    elseif expand("%:e") == 'go'
""        call setline(1, '// ====================================')
""        call setline(2, '')
""        call setline(3, '// Author:            韩孝龙')
""        call setline(4, '// Email:             18301805881@163.com')
""        call setline(5, '// Created Time:      '.strftime("%F %T"))
""        call setline(6, '// Description:       ')
""        call setline(7, '')
""        call setline(8, '// ====================================')
""    endif
""endfunc
""
"""新建文件后，自动定位到文件末尾
""autocmd BufNewFile * normal G
""



"==============================================================================
" 搜索
"==============================================================================
set hlsearch " 高亮显示搜索结果
set incsearch " 每输入一个字符，就自动跳到第一个配置的结果




"==============================================================================
" 编辑
"==============================================================================
set nobackup " 不创建备份文件 该文件的标志是，原文件名的末尾，加了一个波浪号
set noswapfile " 不创建交换文件，交换文件的作用是系统崩溃时恢复文件，文件的开头是. 结尾是.swp
set noundofile "不生成.filename.un~ 文件
set autochdir " 自动切换工作目录
set autoread " 打开文件监视，如果在编辑过程中文件发生外部改变，会提示




"==============================================================================
" 自动补全
"==============================================================================
inoremap ( ()<LEFT>
inoremap [ []<LEFT>
inoremap " ""<LEFT>
inoremap ' ''<LEFT>
inoremap { {}<LEFT>
" imap { {}<ESC>i<CR><ESC>O




"==============================================================================
" 主题配色 
"==============================================================================
" 开启24bit的颜色，开启这个颜色会更漂亮一些
set termguicolors






" ==== statusline begin
set statusline=
set statusline+=%7*\[%n]                                  "buffernr
set statusline+=%1*\ %<%F\                                "文件路径
set statusline+=%2*\ %y\                                  "文件类型
set statusline+=%3*\ %{''.(&fenc!=''?&fenc:&enc).''}      "编码1
set statusline+=%3*\ %{(&bomb?\",BOM\":\"\")}\            "编码2
set statusline+=%4*\ %{&ff}\                              "文件系统(dos/unix..) 
set statusline+=%5*\ %{&spelllang}\%{HighlightSearch()}\  "语言 & 是否高亮，H表示高亮?
set statusline+=%8*\ %=\ row:%l/%L\ (%03p%%)\             "光标所在行号/总行数 (百分比)
set statusline+=%9*\ col:%03c\                            "光标所在列
set statusline+=%0*\ \ %m%r%w\ %P\ \                      "Modified? Read only? Top/bottom
function! HighlightSearch()
    if &hls
        return 'H'
    else
        return ''
    endif
endfunction
hi User1 ctermfg=white  ctermbg=darkgray
hi User2 ctermfg=blue  ctermbg=58
hi User3 ctermfg=green  ctermbg=100
hi User4 ctermfg=black  ctermbg=95
hi User5 ctermfg=white  ctermbg=darkyellow
hi User7 ctermfg=black  ctermbg=blue  cterm=bold
hi User8 ctermfg=231  ctermbg=darkgray
"hi User9 ctermfg=#ffffff  ctermbg=#810085
hi User0 ctermfg=yellow  ctermbg=138
" ==== statusline end


" y直接复制
set clipboard=unnamedplus

" wsl vim复制到win剪切板
map <F3> : call CopyToWindows()<CR>
map! <F3> <ESC> : call CopyToWindows()<CR>
func! CopyToWindows()
    exec "w"
    exec "!cat % |/mnt/c/Windows/System32/clip.exe"
endfunc


" ==== nerdtree begin

" map a specific key or shortcut to open NERDTree
map 1 :NERDTreeToggle<CR>

" open a NERDTree automatically when vim starts up
autocmd vimenter * NERDTree

" ==== nerdtree end



" ==== vim-instant-markdown begin

filetype plugin on
"Uncomment to override defaults:
"let g:instant_markdown_slow = 1
let g:instant_markdown_autostart = 1
"let g:instant_markdown_open_to_the_world = 1
"let g:instant_markdown_allow_unsafe_content = 1
"let g:instant_markdown_allow_external_content = 0
"let g:instant_markdown_mathjax = 1
"let g:instant_markdown_logfile = '/tmp/instant_markdown.log'
"let g:instant_markdown_autoscroll = 0
"let g:instant_markdown_port = 8888
"let g:instant_markdown_python = 1

" ==== vim-instant-markdown end




"==============================================================================
" tagbar
"==============================================================================
nmap <F9> :TagbarToggle<CR>



"==============================================================================
" vim-snippets
"==============================================================================
"插入模式下直接通过ii键来触发UltiSnips的代码块补全
let g:UltiSnipsExpandTrigger="ii"

"iI弹出UltiSnips的可用列表,不常用的, 所以这里设置成了特殊的iI映射
let g:UltiSnipsListSnippets="iI"

"II跳转的到下一个代码块可编辑区
let g:UltiSnipsJumpForwardTrigger="II"

"OO跳转到上一个代码块可编辑区

let g:UltiSnipsJumpBackwardTrigger="OO"


